package token

import (
	"context"
)

type Service interface {
	// 颁发
	IssueToken(context.Context, *IssueTokenRequest) (*Token, error)
	// 撤销
	RevolkToken(context.Context, *RevolkTokenRequest) (*Token, error)
	// 校验
	ValidateToken(context.Context, *ValidateTokenRequest) (*Token, error)
}

type (
	IssueTokenRequest struct {
		Username string `json:"username,omitempty"`
		Password string `json:"password,omitempty"`
	}

	RevolkTokenRequest struct {
		AccessToken  string `json:"access_token,omitempty"`
		RefreshToken string `json:"refresh_token,omitempty"`
	}
	ValidateTokenRequest struct {
		AccessToken string `json:"access_token,omitempty"`
	}
)

func NewIssueTokenRequest(username, password string) *IssueTokenRequest {
	return &IssueTokenRequest{
		Username: username,
		Password: password,
	}
}

func NewValidateTokenRequest(accessToken string) *ValidateTokenRequest {
	return &ValidateTokenRequest{
		AccessToken: accessToken,
	}
}

func NewRevolkTokenRequest(accessToken, refreshToken string) *RevolkTokenRequest {
	return &RevolkTokenRequest{
		AccessToken:  accessToken,
		RefreshToken: refreshToken,
	}
}
